<template>
  <el-dialog v-model="dialogVisible" title="新建文件夹">
    <el-form :model="form">
      <el-form-item label="文件夹名称">
        <el-input v-model="form.name" />
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="handleConfirm">确定</el-button>
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { computed, ref } from 'vue'

const props = defineProps<{
  modelValue: boolean
}>()

const emit = defineEmits<{
  (e: 'update:modelValue', value: boolean): void
  (e: 'confirm', name: string): void
}>()

const dialogVisible = computed({
  get: () => props.modelValue,
  set: (value) => emit('update:modelValue', value)
})

const form = ref({
  name: ''
})

const handleConfirm = () => {
  if (form.value.name) {
    emit('confirm', form.value.name)
    form.value.name = ''
  }
}

// 监听对话框关闭，重置表单
watch(dialogVisible, (val) => {
  if (!val) {
    form.value.name = ''
  }
})
</script> 